<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            //删除按钮单击事件
            $("a[name='delete']").click(function () {
                var pid = $(this).attr("pid");
                if (confirm("确定要删除该信息吗？")){
                    $.get("/person/delete","id="+pid,function (result) {
                        if (result == 'success'){
                            alert("删除信息成功！");
                            location.href = location.href;
                        }else{
                            alert("删除失败，请稍后再试！");
                        }
                    });
                }
            })
        })
    </script>
</head>
<body>
<div align="center">
    <h2>员工信息</h2>
    <table border="1" cellspacing="0" width="60%">
        <tr align="center">
            <th>编号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>等级</th>
            <th>部门</th>
            <th>操作</th>
        </tr>
        <tr th:each="p:${list}" align="center">
            <td th:text="${p.id}"></td>
            <td th:text="${p.name}"></td>
            <td th:text="${p.gender==1?'男':'女'}"></td>
            <td th:text="${p.age}"></td>
            <td th:switch="${p.rank}">
                <span th:case="1" th:text="1级"></span>
                <span th:case="2" th:text="2级"></span>
                <span th:case="3" th:text="3级"></span>
                <span th:case="4" th:text="4级"></span>
                <span th:case="5" th:text="5级"></span>
            </td>
            <td th:text="${p.department}"></td>
            <td>
                <a th:href="@{/person/toUpdate(id=${p.id})}">修改</a>
                <a name = "delete" th:pid="${p.id}">删除</a>
            </td>
        </tr>
    </table>
    <p>
        <a th:href="@{/person/toSave}">添加人员</a>
    </p>
</div>
</body>
</html>